define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'set/index' + location.search,
                    add_url: 'set/add',
                    edit_url: 'set/edit',
                    del_url: 'set/del',
                    multi_url: 'set/multi',
                    import_url: 'set/import',
                    table: 'set',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'merchant', title: __('Merchant'), operate:'BETWEEN'},
                        {field: 'register', title: __('Register'), operate:'BETWEEN'},
                        {field: 'service', title: __('Service'), operate:'BETWEEN'},
                        {field: 'face', title: __('Face'), operate:'BETWEEN'},
                        {field: 'referral', title: __('Referral'), operate:'BETWEEN'},
                        {field: 'prescription', title: __('Prescription'), operate:'BETWEEN'},
                        {field: 'reward', title: __('Reward'), operate:'BETWEEN'},
                        {field: 'integal', title: __('Integal')},
                        {field: 'integal_1', title: __('Integal_1')},
                        {field: 'share', title: __('Share')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'recharge', title: __('Recharge'), operate:'BETWEEN'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'back_hour', title: __('Back_hour')},
                        {field: 'user_hour', title: __('User_hour')},
                        {field: 'consultation_hour', title: __('Consultation_hour')},
                        {field: 'time', title: __('Time'), operate: 'LIKE'},
                        {field: 'interval', title: __('Interval')},
                        {field: 'chat_time', title: __('Chat_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'consultation_fee', title: __('Consultation_fee')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'txyappid', title: __('Txyappid'), operate: 'LIKE'},
                        {field: 'txyappsecret', title: __('Txyappsecret'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});